package com.ibm.risk.irmp.base.dict.dao;

import com.ibm.risk.irmp.base.dict.entity.BaseDictItem;
import com.ibm.risk.irmp.common.vo.CodeLabelVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BaseDictItemRepository extends JpaRepository<BaseDictItem, String> {

    @Query(value = "from BaseDictItem di where di.parentId is null and di.groupCode != 'SYSTEM_CONFIG' order by di.seq")
    List<BaseDictItem> getDataByParentId();

    List<BaseDictItem> findByGroupCodeAndIsDefault(String group, boolean isDefalut);

//    @Query(value = "from BaseDictItem t join BaseDictItem p on t.parentId = p.id where t.group=:group")
//    List<BaseDictItem> findBygroupLevel2(@Param("group") String group);

    List<BaseDictItem> findByGroupCodeAndParentIdIsNullOrderBySeq(String group);

    List<CodeLabelVo> findByGroupCodeOrderBySeq(String group);
    List<BaseDictItem> getBaseDictItemByGroupCodeOrderBySeq(String group);

    List<CodeLabelVo> findByGroupCodeAndCategoryOrderBySeq(String group, String category);

    List<BaseDictItem> findByGroupCode(String group);

    void deleteByGroupCode(String group);

    void deleteByParentId(String parentId);

}
